package com.a85.wxhelper.util;

import android.database.Cursor;
import android.util.Log;

import com.a85.wxhelper.bean.ContactInfo;

/**
 * @author hejiangwei
 * Created at 2018/8/9.
 */
public class Tools {
    private static final String TAG = Tools.class.getName();


    public static ContactInfo getInfoFromCursor(Cursor cursor) {
        cursor.moveToFirst();
        ContactInfo info = null;
        String[] columnNames = cursor.getColumnNames();
        if (columnNames != null) {
            int length = columnNames.length;
            info=new ContactInfo();
            for (int i = 0; i < length; i++) {
                switch (columnNames[i]) {
                    case "rowid":
                        info.setRowid(cursor.getLong(i));
                        break;
                    case  "username":

                        info.setUsername(cursor.getString(i));
                        break;
                    case  "alias":

                        info.setAlias(cursor.getString(i));
                        break;
                    case  "conRemark":

                        info.setConRemark(cursor.getString(i));
                        break;
                    case  "domainList":

                        info.setDomainList(cursor.getString(i));
                        break;
                    case  "nickname":

                        info.setNickname(cursor.getString(i));
                        break;
                    case  "pyInitial":

                        info.setPyInitial(cursor.getString(i));
                        break;
                    case  "quanPin":

                        info.setQuanPin(cursor.getString(i));
                        break;
                    case  "showHead":

                        info.setShowHead(cursor.getInt(i));
                        break;
                    case  "type":

                        info.setType(cursor.getInt(i));
                        break;
                    case  "weiboFlag":

                        info.setWeiboFlag(cursor.getInt(i));
                        break;
                    case  "weiboNickname":

                        info.setWeiboNickname(cursor.getString(i));
                        break;
                    case  "conRemarkPYFull":

                        info.setConRemarkPYFull(cursor.getString(i));
                        break;
                    case  "conRemarkPYShort":

                        info.setConRemarkPYShort(cursor.getString(i));
                        break;

                    case  "lvbuff":
                        //地区国家性别等信息
                        byte[] arr=cursor.getBlob(i);
                        getInfo(arr,info);
                        break;
                    case  "verifyFlag":

                        info.setVerifyFlag(cursor.getInt(i));
                        break;
                    case  "encryptUsername":

                        info.setEncryptUsername(cursor.getString(i));
                        break;
                    case  "chatroomFlag":

                        info.setChatroomFlag(cursor.getInt(i));
                        break;
                    case  "deleteFlag":

                        info.setDeleteFlag(cursor.getInt(i));
                        break;


                    case  "contactLabelIds":

                        info.setContactLabelIds(cursor.getString(i));
                        break;
                    case  "descWordingId":

                        info.setDescWordingId(cursor.getString(i));
                        break;
                    case  "openImAppid":

                        info.setOpenImAppid(cursor.getString(i));
                        break;

                }
            }

            Log.e(TAG, "getInfoFromCursor: "+Constants.beanToString(info) );
        }
        return info;
    }


    //ContactInfo
    public static void getInfo(byte[] field_lvbuff,ContactInfo info) {
        try {
            if (field_lvbuff != null && field_lvbuff.length != 0) {
                ByteInfoUtil u = new ByteInfoUtil();
                int by = u.by(field_lvbuff);
                if (by != 0) {
                    return;
                }


                int csA = u.getInt();
                int sex = u.getInt();
                String csB = u.getString();
                long csC = u.getLong();
                int uin = u.getInt();
                String csD = u.getString();
                String bTi = u.getString();
                int csE = u.getInt();
                int csF = u.getInt();
                String csG = u.getString();
                String csH = u.getString();
                int csI = u.getInt();
                int csJ = u.getInt();
                String signature = u.getString();
                String csK = u.getString();
                String csL = u.getString();
                String csM = u.getString();
                int csN = u.getInt();
                int source = u.getInt();
                String csO = u.getString();
                int field_verifyFlag = u.getInt();
                String csP = u.getString();
                String csQ = null;
                if (!u.chD()) {
                    csQ = u.getString();
                }
                if (!u.chD()) {
                    int csR = u.getInt();
                }
                if (!u.chD()) {
                    int csS = u.getInt();
                }
                if (!u.chD()) {
                    String csT = u.getString();
                }
                if (!u.chD()) {
                    String csU = u.getString();
                }
                if (!u.chD()) {
                    String csV = u.getString();
                }
                if (!u.chD()) {
                    String csW = u.getString();
                }
                if (!u.chD()) {
                    String csX = u.getString();
                }
                if (!u.chD()) {
                    String csY = u.getString();
                }
                if (!u.chD()) {
                    String csZ = u.getString();
                }
                if (!u.chD()) {
                    String cta = u.getString();
                }
                if (!u.chD()) {
                    int ctb = u.getInt();
                }
                if (!u.chD()) {
                    String ctc = u.getString();
                }
                if (!u.chD()) {
                    int ctd = u.getInt();
                }
                if (!u.chD()) {
                    String cte = u.getString();
                }
                info.setSex(sex);
                info.setSignature(signature);
                info.setArea(csK);
                info.setCity(csL);
                info.setLocation(csQ);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }






    public static void getInfo(byte[] field_lvbuff) {
        try {
            if (field_lvbuff != null && field_lvbuff.length != 0) {
                ByteInfoUtil u = new ByteInfoUtil();
                int by = u.by(field_lvbuff);
                if (by != 0) {
                    return;
                }


                String csA = u.getString();
                String sex = u.getString();
                String csB = u.getString();
                Log.e(TAG, "getInfo===content--- "+csA+"\n"+
                        sex+"\n"+
                        csB+"\n"
                );
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
